home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / cnet / cn305c_2.lha / workbench / c / ReDMS next >
Text File  |  1994-01-03  |  3KB  |  83 lines

  1. /* ReDMS by Shawn McNeece aka Powerslave */
  2. pragma('P',-1)    /*change task priority to not take over amiga */
  3.  
  4. parse arg cliargs    /* if arguments, then pass to cliargs */
  5. pathf=word(cliargs,1)   /*extract path and filename from args */
  6. fn=word(cliargs,2)      /*extract filename with extension stripped */
  7. path=left(pathf,length(pathf)-length(fn)-4)  /*find current path from args*/
  8. rez="pipe:"||fn                              /* create a pipe: name thats orignal by using the upload file name */
  9. cmstr="run dms >"||rez" view "||pathf        /*build a command string to send to dos
  10.                                                It will end up looking like:
  11.                                            run dms >pipe:filename view udbase0:Uploads/filename.dms */
  12. address command cmstr   /* send the string cmstr to dos */
  13. address command 'wait'  /* have script wait 1 second while PIPE opens */
  14.             /* 68030 Users may be able to delete that line*/
  15. rc = OPEN(res,rez,'R')  /* open pipe: for reading */
  16. if rc < 1 then          /*abort if PIPE: cant be opened */
  17. do
  18. say '\c2Error, \c5No Results Created.'
  19. close(res);
  20. exit
  21. end
  22.  
  23. i=0
  24. do until eof(res)
  25. i=i+1;ln.i = READLN(res)  /* read in all of pipe:'s output */
  26. end              /* place into stem varible */
  27. close(res)               
  28. Say 'Analyzing '||pathf||'...'
  29. tstwrd=word(ln.16,4)              /* get compression mode */
  30. size = word(ln.7,3)          /* get file size in bytes */
  31. say 'Compression Used:' tstwrd 'Size:' size
  32.  
  33. /* test compression mode and reconvert if not equal to any of these */
  34. if tstwrd ~="HEAVY1" & tstwrd ~="HEAVY2" & tstwrd ~="DEEP" then 
  35. do /* start of main DO...END*/
  36.  
  37.  say 'Converting '||fn||'.dms to better compression mode'
  38.  cstr="dms repack "pathf" to "path||fn||"tmp.dms cmode best"
  39.  address command cstr
  40.  
  41.  /* view new .dms file for comparison */
  42.  cmstr="run dms >"||rez" view "||path||fn||"tmp.dms"
  43.  address command cmstr
  44.  
  45.  rc = OPEN(res,rez,'R')  /*open pipe: again */
  46.  if rc < 1 then do
  47.    say '\c2Error, \c5No Results Created.'
  48.    close(res);
  49.  end
  50.  
  51.  i=0
  52.   do until eof(res)  /* read pipe again */
  53.      i=i+1;ln.i = READLN(res)
  54.   end
  55.  close(res)
  56.  size2 = word(ln.7,3)   /*get new file size */
  57.  tstwrd2=word(ln.16,4)  /*get new compression mode */
  58.  if size <=0 then size = size2+1  /*sometimes dms view will report size of 0 */
  59.  savings=size-size2
  60.  say 'Filename:      ' pathf
  61.  say 'Original CMODE:' tstwrd 
  62.  say 'New CMODE:     ' tstwrd2
  63.  say 'Original size: ' size 
  64.  say 'Converted size:' size2
  65.    if savings >=1 & size2 ~=0 then do
  66.       cstr="delete "pathf  /*delete old dms */
  67.         address command cstr
  68.            cstr="rename "||path||fn||"tmp.dms "||path||fn||".dms"
  69.            address command cstr     /* rename new compressed to old filename */
  70.          say "Byte Savings="savings 
  71.        pct=left(size2 / size,4)*100
  72.      say "Percentage gained=" 100-pct
  73.    end
  74.   else do
  75.        cstr="delete "||path||fn||".dms"  /*delete new archvie just incase its */
  76.        address command cstr        /* bigger than the original */
  77.      end
  78.  
  79. end /* end main DO */
  80. say 'Done'
  81. exit(0)
  82.  
  83.